package com.jcl.recruit.channel.mapper;

import com.jcl.recruit.channel.model.ChannelNet;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @ClassName ChannelNetMapper

 * @Author yyliu
 * @Date 2018/9/11 16:39
 * @Version 1.0
 **/
public interface ChannelNetMapper {

    @Select({
            "<script>",
            "select * from channel_net " ,
            "<where>",
            "<if test=\"null != corpCode\">",
            "corp_code = #{corpCode} ",
            "</if>",
            "<if test=\"null != userId\">",
            " and add_user = #{userId} ",
            "</if>",
            " and (status is null or status &lt; 2) ",
            "</where>",
            "</script>",
    })
    List<ChannelNet> selectList(@Param("corpCode") String corpCode, @Param("userId") String userId);

    @Select({
            "<script>",
            "select * from channel_net " ,
            "<where>",
            "<if test=\"null != corpCode\">",
            "corp_code = #{corpCode} ",
            "</if>",
            "<if test=\"null != account\">",
            " and account = #{account} ",
            "</if>",
            "<if test=\"null != channelType\">",
            " and channel_type = #{channelType} ",
            "</if>",
            "<if test=\"null != status\">",
            " and status = #{status} ",
            "</if>",
            "</where>",
            "</script>",
    })
    List<ChannelNet> findList(@Param("corpCode") String corpCode,
                              @Param("account") String account,
                              @Param("channelType") String channelType,
                              @Param("status") Integer status);

    @Select({
            "select * from channel_net where corp_code = #{corpCode} and id = #{id}"
    })
    ChannelNet findOne(@Param("corpCode") String corpCode,
                       @Param("id") Integer id);

    @Select({
            "select * from channel_net where corp_code = #{corpCode} and account_no = #{accountNo}"
    })
    ChannelNet findOneByAccountNo(@Param("corpCode") String corpCode,
                                  @Param("accountNo") String accountNo);

    @InsertProvider(type = ChannelNetProvider.class, method = "insertSelective")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int addChannelNet(ChannelNet channelNet);

    @UpdateProvider(type = ChannelNetProvider.class, method = "updateSelective")
    int updateChannelNet(ChannelNet channelNet);

    @Update({
            "update channel_net set status = #{status} where corp_code = #{corpCode} and id = #{id}"
    })
    int deleteChannelNet(@Param("corpCode") String corpCode, @Param("id") Integer id, @Param("status") Integer status);
}
